package com.sky.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Slf4j
@Aspect
public class AddLogAspect {

    @Pointcut("execution(* com.sky.controller..*.*(..))")
    public void Point() {
    }


    @Around("Point()")
    public Object addLog(ProceedingJoinPoint joinPoint) {
        log.info("开始为控制层记录日志");
        if (joinPoint.getArgs() != null && joinPoint.getArgs().length != 0) {
            Object arg = joinPoint.getArgs()[0];
            log.info("接收到的参数为:{}", arg);
        }
        Object result = null;
        try {
            result = joinPoint.proceed();
        } catch (Throwable e) {
            log.error("添加日志...代理方法执行失败...", e);
        }
        return result;
    }
}
